use proto_lib::proto_common::user_service::user_service_server::UserService;
use proto_lib::proto_common::user_service::{CreateUserRequest, CreateUserResponse, DeleteUserRequest, DeleteUserResponse, GetUserRequest, GetUserResponse, UpdateUserRequest, UpdateUserResponse, User};
use tonic::{Request, Response, Status};

#[derive(Debug, Default)]
pub struct GrpcUserService {} // 实现UserService trait 根据业务完成grpc服务端的代码

#[tonic::async_trait]
impl UserService for GrpcUserService {
    async fn create_user(
        &self,
        request: Request<CreateUserRequest>,
    ) -> Result<Response<CreateUserResponse>, Status> {
        todo!()
    }

    async fn get_user(
        &self,
        request: Request<GetUserRequest>,
    ) -> Result<Response<GetUserResponse>, Status> {

        println!("get_user request: {:?}", request);
        let mut reply = GetUserResponse::default();
        reply.user = Option::from(User {
            id: "1".to_string(),
            name: "xieyf".to_string(),
            email: "xieyf@qq.com".to_string(),
            age: 18,
        });
        Ok(Response::new(reply)) // Send back our formatted greeting
    }

    async fn update_user(
        &self,
        request: Request<UpdateUserRequest>,
    ) -> Result<Response<UpdateUserResponse>, Status> {
        todo!()
    }

    async fn delete_user(
        &self,
        request: Request<DeleteUserRequest>,
    ) -> Result<Response<DeleteUserResponse>, Status> {
        todo!()
    }
}
